package com.codingapi.auto.deploy.service;

import com.alibaba.fastjson.JSON;
import com.codingapi.auto.deploy.ato.ServerConfig;
import com.codingapi.auto.deploy.client.SSHClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author modificial
 * @date 2018/7/23
 * @company codingApi
 * @description 执行脚本返回结果
 */
@Service
public class DeployService {
    private static final Logger LOGGER = LoggerFactory.getLogger(DeployService.class);

    @Autowired
    private ServerConfig serverConfig;

    /**
     * 执行脚本返回结果信息
     *
     * @return
     */
    public List<String> deploy() {
        String command = "sh " + serverConfig.getPath();
        String cmd="cat "+serverConfig.getHtml();
        SSHClient.exeCommand(serverConfig.getHost(), serverConfig.getPort(), serverConfig.getUserName(), serverConfig.getPassWord(), command);
        List<String> message=SSHClient.exeCommand(serverConfig.getHost(), serverConfig.getPort(), serverConfig.getUserName(), serverConfig.getPassWord(),cmd);
        LOGGER.info("返回信息为："+JSON.toJSONString(message));
        return message;
    }
}
